/**
 *******************************************************************************
 * @brief       Provide a brief description of the module here (Single line).
 * 
 * @author      Ashwin Vijayakumar
 * 
 * @file        McalGpio_Driver.h
 * 
 * @version     V1.0.0
 * 
 * @date        Jan 29, 2012 10:22:38 PM
 * 
 * @details     Provide a detailed description of the module here (Multi-line).
 * 
 * @pre         Mention any preconditions required to use this module.
 * 
 * @bug         List any bugs in this module.
 * 
 * @note        List any odd modes while using this module.
 * 
 * @warning     List any warnings against using the objects of this module.
 *******************************************************************************
 * @copyright 2012
 * <a href="http://www.afflatustech.com">Afflatus Techtronics</a>
 * and <a href="http://www.ashwinvijayakumar.co.nr">Ashwin Vijayakumar</a>
 * @n@n
 * This work is licensed under the Creative Commons
 * Attribution-NonCommercial-ShareAlike 3.0 Unported License. To view a copy
 * of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or
 * send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain
 * View, California, 94041, USA.
 *******************************************************************************
 */

/**@cond Include guard symbol - Protect against multiple inclusions  @endcond */

#ifndef MCALGPIO_H_
#define MCALGPIO_H_

/**@cond ***********************************************************************
 * Add #include "McalGpio_Driver.h" in source files that need access to the below
 * listed declarations.
 ******************************************************************* @endcond */

/**@cond -----------------------------------------------------------------------
 * Includes section
 * Add all #include here.
 * ----------------------------------------------------------------- @endcond */

/**@cond System headers -------------------------------------------- @endcond */

/**@cond Local headers --------------------------------------------- @endcond */
#include "Platform_Types.h"
#include "Std_types.h"

/**@cond -----------------------------------------------------------------------
 * typedef section (Project scope)
 * Add typedef's with project scope here.
 * Capitalization: Upper_Camel_Case.
 * ----------------------------------------------------------------- @endcond */

/* Standard GPIO Pin Definitions */
/**
 * @brief Standard GPIO Pin Definitions.
 * @details This type shall be used to reference individual pins of a GPIO port
 * of width up to 32 bits long.
 * @{
 */

typedef enum
{
  PIN0          = 0x00000001,           /**< PIN0. */
  PIN1          = 0x00000002,           /**< PIN1. */
  PIN2          = 0x00000004,           /**< PIN2. */
  PIN3          = 0x00000008,           /**< PIN3. */
  PIN4          = 0x00000010,           /**< PIN4. */
  PIN5          = 0x00000020,           /**< PIN5. */
  PIN6          = 0x00000040,           /**< PIN6. */
  PIN7          = 0x00000080,           /**< PIN7. */
  PIN8          = 0x00000100,           /**< PIN8. */
  PIN9          = 0x00000200,           /**< PIN9. */
  PIN10         = 0x00000400,           /**< PIN10. */
  PIN11         = 0x00000800,           /**< PIN11. */
  PIN12         = 0x00001000,           /**< PIN12. */
  PIN13         = 0x00002000,           /**< PIN13. */
  PIN14         = 0x00004000,           /**< PIN14. */
  PIN15         = 0x00008000,           /**< PIN15. */
  PIN16         = 0x00010000,           /**< PIN16. */
  PIN17         = 0x00020000,           /**< PIN17. */
  PIN18         = 0x00040000,           /**< PIN18. */
  PIN19         = 0x00080000,           /**< PIN19. */
  PIN20         = 0x00100000,           /**< PIN20. */
  PIN21         = 0x00200000,           /**< PIN21. */
  PIN22         = 0x00400000,           /**< PIN22. */
  PIN23         = 0x00800000,           /**< PIN23. */
  PIN24         = 0x01000000,           /**< PIN24. */
  PIN25         = 0x02000000,           /**< PIN25. */
  PIN26         = 0x04000000,           /**< PIN26. */
  PIN27         = 0x08000000,           /**< PIN27. */
  PIN28         = 0x10000000,           /**< PIN28. */
  PIN29         = 0x20000000,           /**< PIN29. */
  PIN30         = 0x40000000,           /**< PIN30. */
  PIN31         = 0x80000000,           /**< PIN31. */
  PIN8MSK       = 0x000000FF,           /**< PINs 0 thru 7 */
  PIN16MSK      = 0x0000FF00,           /**< PINs 8 thru 15 */
  PIN24MSK      = 0x00FF0000,           /**< PINs 16 thru 23 */
  PIN32MSK      = 0xFF000000            /**< PINs 24 thru 31 */
} McalGpio_PinType;

/**
 * @}
 */

/**
 * @brief GPIO Pin Mode Type
 * @details This type shall be used to declare variables which hold the
 * different modes (input, output or alternate) of an IO pin.
 */
typedef enum
{
  GPIO_MODE_IN,
  GPIO_MODE_OUT,
  GPIO_MODE_AF
}McalGpio_PinModeType;

/**
 * @brief GPIO Pin Value Type
 * @details This type shall be used to declare a variable whose value will be
 * either assigned to, or read from, a GPIO Pin.
 */
typedef uint8_t  McalGpio_PinValueType;

/**
 * @brief GPIO Pin Direction Type.
 * @details This type shall be used to declare a port pin as input or output.
 */
typedef enum
{
  GPIO_PIN_OUT  = 0,            /**< GPIO Pin declared as output. */
  GPIO_PIN_IN   = 1             /**< GPIO Pin declared as input. */
} McalGpio_PinDirectionType;

/**
 * @brief GPIO Configuration Type.
 * @details This type shall be used to declare an IO port's initialization
 * structure.
 */
typedef struct
{
  uint8_t                       McalGpio_Port;              /**< Port to be configured. */
  McalGpio_PinType              McalGpio_Pin;               /**< Pin(s) to be configured. */
  McalGpio_PinModeType          McalGpio_PinMode;           /**< Input, Output or Alternate. */
  McalGpio_PinDirectionType     McalGpio_PinDirection;      /**< Input or Output. */
} McalGpio_ConfigType;

/**@cond -----------------------------------------------------------------------
 * Constants section (Project scope)
 * Add all constants with project scope here.
 * Capitalization: ALL_CAPS.
 * ----------------------------------------------------------------- @endcond */

/**@cond -----------------------------------------------------------------------
 * Macros section (Project scope)
 * Add all macros with project scope here.
 * Capitalization: ALL_CAPS.
 * ----------------------------------------------------------------- @endcond */

#define MCALGPIO_WIDTH                                          8

#define McalGpio_SetPinDirection(DirId, Pins, Direction)        \
    do                                                          \
    {                                                           \
        (Direction == GPIO_PIN_OUT) ?                           \
            (DirId &= ~Pins) :                                  \
            (DirId |= Pins);                                    \
    } while(0)

#define McalGpio_ReadPort(PortId)                               (PortId)

#define McalGpio_WritePort(PortId, Level)                       (PortId = Level)

#define McalGpio_ReadPins(PortId, Pins)                         (PortId & Pins)

#define McalGpio_WritePins(PortId, Pins, Level)                 \
    do                                                          \
    {                                                           \
        (!Level) ?                                              \
            (PortId &= ~Pins) :                                 \
            (PortId |= Pins);                                   \
    } while(0)

#define McalGpio_SetPins(PortId, Pins)                          (PortId |= Pins)

#define McalGpio_ResetPins(PortId, Pins)                        (PortId &= ~Pins)

#define McalGpio_TogglePins(PortId, Pins)                       (PortId ^= Pins)

/**@cond -----------------------------------------------------------------------
 * Global variables section (Project scope)
 * Add global variables with project scope here. 
 * Capitalization: lower_case.
 * Declare them with 'extern' keyword.
 * ----------------------------------------------------------------- @endcond */

/**@cond -----------------------------------------------------------------------
 * Function prototypes section (Project scope)
 * Add prototypes for all functions with project scope here. 
 * Capitalization: lower_Camel_Case.
 * ----------------------------------------------------------------- @endcond */

/**@cond -----------------------------------------------------------------------
 * Getter/setter prototype section (Project scope)
 * Add prototypes for getter/setter methods here.
 * Capitalization: get_Camel_Case/is_Camel_Case/set_Camel_Case. 
 * ----------------------------------------------------------------- @endcond */


#endif /* MCALGPIO_H_ */


/** END OF FILE ********************* Copyright (C) 2012 Afflatus Techtronics */
